package com.ruoyi.printer.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.printer.domain.PrinterShop;
import com.ruoyi.printer.domain.vo.PrinterShopVo;
import com.ruoyi.printer.service.IPrinterShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 店铺管理Controller
 * 
 * @author yanyi
 * @date 2023-07-07
 */
@RestController
@RequestMapping("/printer/shop")
public class PrinterShopController extends BaseController
{
    @Autowired
    private IPrinterShopService printerShopService;

    /**
     * 查询店铺管理列表
     */
    @PreAuthorize("@ss.hasPermi('printer:shop:list')")
    @GetMapping("/list")
    public TableDataInfo list(PrinterShop printerShop)
    {
        startPage();
        List<PrinterShopVo> list = printerShopService.selectPrinterShopList(printerShop);
        return getDataTable(list);
    }

    /**
     * 导出店铺管理列表
     */
    @PreAuthorize("@ss.hasPermi('printer:shop:export')")
    @Log(title = "店铺管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PrinterShop printerShop)
    {
        List<PrinterShopVo> list = printerShopService.selectPrinterShopList(printerShop);
        ExcelUtil<PrinterShopVo> util = new ExcelUtil<>(PrinterShopVo.class);
        util.exportExcel(response, list, "店铺管理数据");
    }

    /**
     * 获取店铺管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('printer:shop:query')")
    @GetMapping(value = "/{shopId}")
    public AjaxResult getInfo(@PathVariable("shopId") Long shopId)
    {
        return success(printerShopService.selectPrinterShopByShopId(shopId));
    }

    /**
     * 新增店铺管理
     */
    @PreAuthorize("@ss.hasPermi('printer:shop:add')")
    @Log(title = "店铺管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PrinterShop printerShop)
    {
        return toAjax(printerShopService.insertPrinterShop(printerShop));
    }

    /**
     * 修改店铺管理
     */
    @PreAuthorize("@ss.hasPermi('printer:shop:edit')")
    @Log(title = "店铺管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PrinterShop printerShop)
    {
        return toAjax(printerShopService.updatePrinterShop(printerShop));
    }

    /**
     * 删除店铺管理
     */
    @PreAuthorize("@ss.hasPermi('printer:shop:remove')")
    @Log(title = "店铺管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{shopIds}")
    public AjaxResult remove(@PathVariable Long[] shopIds)
    {
        return toAjax(printerShopService.deletePrinterShopByShopIds(shopIds));
    }
}
